Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace transmute to box from/into #503

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

noname0310
Copy link

Summary

According to the rust documentation , std::mem::transmute is a dangerous function that is very prone to creating undefined behavior and should only be used as a last resort:

Both the argument and the result must be valid at their given type.
Violating this condition leads to undefined behavior.
The compiler will generate code assuming that you, the programmer, ensure that there will never be undefined behavior.
It is therefore your responsibility to guarantee that every value passed to transmute is valid at both types Src and Dst.
Failing to uphold this condition may lead to unexpected and unstable compilation results.
This makes transmute incredibly unsafe. transmute should be the absolute last resort.

And all the transmute functions used so far in this project are simply being used to extend the lifetime of a boxed value. This scenario is common in FFI code, so there are already better functions than std::mem::transmute for this. For example, you can use the pair Box::into_raw and Box::from_raw.

This pull request replaces all std::mem::transmute calls with Box::into_raw and Box::from_raw to make the code safer.

Note

  • All commits must be signed to be merged
  • CI must be passed to be merged

@hkrn
Copy link
Owner

hkrn commented Aug 17, 2024

The changes themselves seem good, but they may require some adjustments considering Rust 2024 compatibility.

https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html

@hkrn hkrn enabled auto-merge (squash) August 20, 2024 12:24
@hkrn hkrn disabled auto-merge August 20, 2024 12:38
@hkrn
Copy link
Owner

hkrn commented Aug 20, 2024

As noted in the pull request template, signatures are required for "every commit". Since this requirement has not been met, I'm unable to merge the pull request.

@noname0310 noname0310 force-pushed the transmute-to-boxfrominto branch from daa3dbc to 8705065 Compare August 21, 2024 02:09
@noname0310
Copy link
Author

I'm sure there's no problem now

@hkrn hkrn enabled auto-merge (squash) August 25, 2024 02:54
Copy link

stale bot commented Nov 27, 2024

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the wontfix label Nov 27, 2024
@stale stale bot removed the wontfix label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants